package com.product.service.impl;

import com.product.service.ProductService;
import com.qfedu.mbg.mapper.*;
import com.qfedu.mbg.model.*;
import com.qfedu.mbg.model.Process;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.Map;

/**
 * @author Z ym
 * @create 2024-07-11 19:24
 * @desc
 */
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductTableMapper productTableMapper;
    @Autowired
    private ProcessFlowMapper processFlowMapper;
    @Autowired
    private ProcessMapper processMapper;
    @Autowired
    private EquipmentLedgerMapper equipmentLedgerMapper;
    @Autowired
    private MaterialsMapper materialsMapper;
    @Autowired
    private IngredientsMapper ingredientsMapper;
    @Autowired
    private CutterMapper cutterMapper;
    @Override
    public List<ProductList> selectProductByCondition(Map<String, Object> map) {
        return productTableMapper.selectSysUserByCondition(map);
    }

    @Override
    public Integer deleteByExample(Integer productId) {
        ProductTableExample example = new ProductTableExample();
        example.createCriteria().andProductIdEqualTo(productId);
        return  productTableMapper.deleteByExample(example);
    }

    @Override
    public Integer insert(ProductTable productTable) {
        return productTableMapper.insert(productTable);
    }

    @Override
    public Integer edit(ProductTable productTable) {
        ProductTable product = productTableMapper.selectByPrimaryKey(productTable.getProductId());
        product.setDescription(productTable.getDescription());
        product.setSize(productTable.getSize());
        product.setMaterialsId(productTable.getMaterialsId());
        product.setTexture(productTable.getTexture());
        return productTableMapper.insert(productTable);
    }

    @Override
    public craftProcess craftProcessShow(Integer productId) {
        return productTableMapper.selectCraftProcessShow(productId);
    }

    @Override
    public List<ProcessFlow> craftProcessList() {
        ProcessFlowExample example = new ProcessFlowExample();
        return processFlowMapper.selectByExample(example);
    }

    @Override
    public List<Process> structureList() {
        ProcessExample processExample = new ProcessExample();
        return processMapper.selectByExample(processExample);
    }

    @Override
    public List<EquipmentLedger> equipmentList() {
        EquipmentLedgerExample ledgerExample = new EquipmentLedgerExample();
        return equipmentLedgerMapper.selectByExample(ledgerExample);
    }

    @Override
    public List<Materials> materialsList() {
        MaterialsExample materialsExample = new MaterialsExample();
        return materialsMapper.selectByExample(materialsExample);
    }

    @Override
    public List<Ingredients> ingredientsList() {
        IngredientsExample ingredientsExample = new IngredientsExample();
        return ingredientsMapper.selectByExample(ingredientsExample);
    }

    @Override
    public List<Cutter> cutterList() {
        CutterExample cutterExample = new CutterExample();
        return cutterMapper.selectByExample(cutterExample);
    }

    @Override
    public Integer equipmentAdd(EquipmentLedger equipmentLedger) {
        return equipmentLedgerMapper.insert(equipmentLedger);
    }

    @Override
    public Integer materialsAdd(Materials materials) {
        return materialsMapper.insert(materials);
    }

    @Override
    public Integer ingredientsAdd(Ingredients ingredients) {
        return ingredientsMapper.insert(ingredients);
    }

    @Override
    public Integer cutterAdd(Cutter cutter) {
        return cutterMapper.insert(cutter);
    }
}
